package moveup;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test01
 * Package: moveup
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-15
 * Time: 21:44
 */

//数组的扩容
public class Test01 {
    public static void main(String[] args) {

        int[] arr = {1,2,3,4,5};
        //将数组长度扩容1倍 并将10，20，30三个数据添加到arr中

        //扩容不能接着数组后面 只能新建
        int[] newArr = new int[arr.length * 2];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        //10，20，30三个数据添加到arr中
        newArr[arr.length] = 10;
        newArr[arr.length + 1] = 20;
        newArr[arr.length + 2] = 30;
        //垃圾回收机制 判断是否存在引用指向它

        arr = newArr;

        System.out.println(Arrays.toString(arr));


    }
}
